package com.jia.train.seat.controller;

import com.jia.train.global.page.PageResponse;
import com.jia.train.global.response.BaseResponse;
import com.jia.train.seat.request.TrainCarriageQueryRequest;
import com.jia.train.seat.request.TrainCarriageSaveRequest;
import com.jia.train.seat.response.TrainCarriageQueryResponse;
import com.jia.train.seat.response.TrainCarriageSaveResponse;
import com.jia.train.seat.service.TrainCarriageService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/carriage")
public class TrainCarriageController {

    @Resource
    private TrainCarriageService trainCarriageService;

    @PostMapping("/insert")
    public BaseResponse<TrainCarriageSaveResponse> insertTrainCarriage(@Valid @RequestBody TrainCarriageSaveRequest request) {
        TrainCarriageSaveResponse response = trainCarriageService.insert(request);
        return new BaseResponse<>(response);
    }

    @GetMapping("/query")
    public BaseResponse<PageResponse<TrainCarriageQueryResponse>> query(@Valid TrainCarriageQueryRequest request) {
        PageResponse<TrainCarriageQueryResponse> responseList = trainCarriageService.selectPage(request);
        return new BaseResponse<>(responseList);
    }

    @DeleteMapping("/delete/{id}")
    public BaseResponse<String> delete(@PathVariable Long id) {
        trainCarriageService.deleteTrainCarriage(id);
        return new BaseResponse<>("success");
    }

}
